home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C++ / Applications / SeeMovieRun 2.0 / Source / CMovie.cp < prev    next >
Encoding:
Text File  |  1995-08-02  |  7.7 KB  |  283 lines  |  [TEXT/KAHL]

  1. /******************************************************************************
  2.  CMovie.c
  3.  
  4.                             The Movie Class
  5.         
  6.         Displays a standard QuickTime Movie.
  7.         
  8.         This is a read-only class that allows you to specify and play a QuickTime
  9.         movie with minimal other features. It is designed to simply allow the
  10.         importation and display of movie files. The movies are controlled by
  11.         the standard movie controller.
  12.         
  13.         This class could be expanded to allow editing and more…
  14.     
  15.     SUPERCLASS = CPane
  16.     
  17.     Copyright © 1992 Joe Zobkiw. All rights reserved.
  18.     Portions Copyright © 1990 Symantec Corporation.  All rights reserved.
  19.  
  20.     Copyright © 1995 Gregory Bonk. All rights reserved.
  21.         Changes upgrade to TPM 7.0.7
  22.  ******************************************************************************/
  23.  
  24. #include "CMovie.h"
  25. #include "CEBCollaborator.h"
  26. #include "Defines.h"
  27. #include <Commands.h>
  28. #include <Global.h>
  29. #include <CPaneBorder.h>
  30. #include <TCLUtilities.h>
  31. #include <TBUtilities.h>
  32.  
  33. extern  CEBCollaborator    *gEBCollaborator;
  34.  
  35. TCL_DEFINE_CLASS_D1(CMovie, CPane);
  36.  
  37. /******************************************************************************
  38.  CMovie
  39.  
  40.  ******************************************************************************/
  41. CMovie::CMovie()
  42. {
  43. // initialize our instance variables
  44.     
  45.     itsMovie = NULL;
  46.     itsMovieRefNum = 0;
  47.     itsController = NULL;
  48.  
  49.     TCL_END_CONSTRUCTOR
  50. }
  51.  
  52.  
  53. /******************************************************************************
  54.  ~CMovie
  55.  
  56.  ******************************************************************************/
  57. CMovie::~CMovie()
  58. {
  59.     TCL_START_DESTRUCTOR
  60.  
  61.     ForgetInstanceVariables();
  62.     CancelDependency(gEBCollaborator);
  63. }
  64.  
  65.  
  66. /******************************************************************************
  67.  ForgetInstanceVariables
  68.  
  69.         clears the instance variables of this class
  70.  ******************************************************************************/
  71. void CMovie::ForgetInstanceVariables(void)
  72. {
  73.     if (itsMovie)
  74.     {
  75.         DisposeMovie(itsMovie);
  76.         itsMovie = NULL;
  77.     }
  78.     if (itsMovieRefNum) 
  79.     {
  80.         CloseMovieFile(itsMovieRefNum);
  81.         itsMovieRefNum = 0;
  82.     }
  83.     if (itsController) 
  84.     {
  85.         DisposeMovieController(itsController);
  86.         itsController = NULL;
  87.     }
  88. }
  89.  
  90. /******************************************************************************
  91.  IMovie
  92.  
  93.         Initialize a Movie object
  94.  ******************************************************************************/
  95. void    CMovie::IMovie(    CView            *anEnclosure,    CBureaucrat        *aSupervisor,
  96.                         short        aWidth,    short        aHeight,
  97.                         short        aHEncl,    short        aVEncl,
  98.                         SizingOption    aHSizing,    SizingOption    aVSizing,    FSSpec     *aMovieSpec)
  99. {
  100.     
  101.     CPane::IPane(anEnclosure, aSupervisor,
  102.                     aWidth, aHeight, aHEncl, aVEncl, aHSizing, aVSizing);
  103.     
  104.     
  105.     SetWantsClicks(true);    // we want to receive clicks
  106.     
  107.     
  108. // we want a simple border in case we decide to resize the frame to be
  109. // smaller than it’s enclosure. this will make it look nicer.
  110.     
  111.     itsBorder = new(CPaneBorder);
  112.     itsBorder->IPaneBorder(kBorderFrame);
  113.  
  114. //    SetCanBeGopher(true);    // we want be a gopher!
  115. //    BecomeGopher(true);
  116.  
  117. // we want to recieve events from gEBCollaborator which is our provider…
  118. // the one whom we depend upon
  119.     
  120.     DependUpon(gEBCollaborator);
  121.  
  122. // if we have a movie to open (the user selected Open… instead of New) then
  123. // open the movie!
  124.     
  125.     if (aMovieSpec)
  126.         ImportMovie(aMovieSpec);
  127. }
  128.  
  129.  
  130. /******************************************************************************
  131.  ProviderChanged
  132.  
  133.     Our Provider has changed
  134. ******************************************************************************/
  135. void CMovie::ProviderChanged( CCollaborator *aProvider, long reason, void* info)
  136. {
  137.     short eventHandled;
  138.  
  139.     switch(reason) 
  140.     {
  141. // kEventRecordReason is the only reason we deal with these days
  142.     case kEventRecordReason:
  143.     
  144.         // we might end up drawing because of this MCPlayer event
  145.         // so we must be sure our port is set up correctly.
  146.             
  147.         Prepare();
  148.             
  149.         // see if the movie controller would like the event or not
  150.             
  151.         eventHandled = MCIsPlayerEvent(itsController, (EventRecord*)info);
  152.         if (eventHandled == TRUE)
  153.             ((EventRecord*)info)->what = nullEvent;                
  154.                 
  155.                 // we handled the event so we change it to a null event
  156.                 // so it is (in effect) ignored elsewhere.
  157.                 
  158.         break;
  159.     default:
  160.         break;
  161.     }
  162.     
  163.     inherited::ProviderChanged(aProvider, reason, info);
  164. }
  165.  
  166. /******************************************************************************
  167.  DoClick  (OVERRIDE)
  168.  
  169.         This will get called if we click outside of the movie but still
  170.         within the Movie Pane (which is currently sticky to the size of the window)
  171.  ******************************************************************************/
  172. void    CMovie::DoClick(Point hitPt, short modifierKeys, long when)
  173. {
  174. // this alert will beep the first two times and show itself the third time
  175. // and thereafter. It will simply remind the user that clicking in the empty
  176. // area of the CMovie Pane is fruitless other than showing this annoying alert.
  177.     
  178.     if (active)
  179.         NoteAlert(kMovieDoClickALRT, nil);
  180. }
  181.  
  182. /******************************************************************************
  183.  ImportMovie
  184.  
  185.         Use the movie pointed to by spec as our movie. This routine imports 
  186.         the given movie, replacing any previous movies that were used in this pane.
  187.         
  188.  ******************************************************************************/
  189. void    CMovie::ImportMovie(FSSpec *aSpec)
  190. {
  191.     Rect            movieRect;
  192.     Boolean            locked;
  193.             
  194.     if (aSpec == NULL)     // hop out if there is no spec to import
  195.         return;
  196.  
  197.     Prepare();    // prepare for drawing, etc.
  198.  
  199.     ForgetInstanceVariables();    // forget our current movie & controller
  200.     
  201.     // open the movie file and create a new movie from the file
  202.     
  203.     FailOSErr(OpenMovieFile(aSpec, &itsMovieRefNum, fsRdPerm));
  204.     FailOSErr(NewMovieFromFile(&itsMovie, itsMovieRefNum, NULL, NULL, newMovieActive, NULL));
  205.     
  206.     // get the bounds for the movie and make sure the top left is 0,0
  207.     // so the movie won't be offset within the window
  208.     
  209.     GetMovieBox(itsMovie, &movieRect);            
  210.     FailOSErr(GetMoviesError());
  211.     OffsetRect(&movieRect,-movieRect.left,-movieRect.top);
  212.     SetMovieBox(itsMovie, &movieRect);            
  213.     FailOSErr(GetMoviesError());
  214.  
  215.     // rewind the movie
  216.     
  217.     GoToBeginningOfMovie(itsMovie);            
  218.     FailOSErr(GetMoviesError());
  219.  
  220.     // create our controller
  221.     
  222.     itsController = NewMovieController(itsMovie, &movieRect, mcWithFrame+mcTopLeftMovie);
  223.     FailOSErr(GetMoviesError());
  224.         
  225.     Refresh();    // redraw ourselves
  226. }
  227.  
  228.  
  229. /******************************************************************************
  230.  Dawdle {OVERRIDE}
  231.  
  232.         Call MoviesTask here if we have a movie and it is playing. MoviesTask()
  233.         handles updating the movie for us. It will update the movie in the background
  234.         also.
  235.         
  236.  ******************************************************************************/
  237. void    CMovie::Dawdle(long    *maxSleep)
  238. {
  239.     if (itsMovie)
  240.     {
  241.         if (!IsMovieDone(itsMovie)) 
  242.         {
  243.             Prepare();                        // get ready to draw
  244.             MoviesTask(itsMovie, 0);            // update the movie
  245.             FailOSErr(GetMoviesError());    // check the error condition
  246.         }
  247.     }
  248. }
  249.  
  250.  
  251. /******************************************************************************
  252.  Draw {OVERRIDE}
  253.  
  254.         Draw a Movie and the controller if need be.
  255.         
  256.  ******************************************************************************/
  257. void    CMovie::Draw(Rect *area)
  258. {
  259.     Rect            tempRect;
  260.     
  261.     
  262.     Prepare();        // prepare to draw
  263.     
  264.     // draw our movie or fill the pane with gray pattern if we have no movie
  265.  
  266.     if (itsMovie) 
  267.     {
  268.         UpdateMovie(itsMovie);                // update the movie next time MoviesTask is called        
  269.         FailOSErr(GetMoviesError());    // check for errors
  270.         MoviesTask(itsMovie, 0);            // actually perform the update
  271.         FailOSErr(GetMoviesError());    // check for errors
  272.     } else 
  273.     {
  274.         LongToQDRect( &aperture, &tempRect);
  275.         FillRect(&tempRect, &gray);
  276.     }
  277.     
  278.     
  279.     if (itsController)     // if we have a controller, draw it here
  280.         MCDraw(itsController, GetMacPort());
  281. }
  282.  
  283.